﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;

public partial class BackGround_CategoryManager : System.Web.UI.Page
{
    Operation operation = new Operation();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            del.Attributes.Add("onclick", "return confirm('是否删除当前分类！')");
            if (Session["Admin"] == null)
            {
                WebMessageBox.Show("会话失效，请重新登录！");
            }
            else
            {
                if (Request.QueryString["id"] != null)
                {
                    if (Request.QueryString["id"].Equals("0"))
                    {
                        WebMessageBox.Show("你不能删除顶级分类！");
                        return;
                    }
                    operation.DeleteCategory(Request.QueryString["id"]);
                }
                BuiltTreeView("0");
            }
        }

    }
    public void BuiltTreeView(string pid)
    {
        TreeNode tp = new TreeNode();
        tp.Value = "0";
        tp.Text = "<b id='" + "0" + "' oncontextmenu='return showmenuie5(event)'> " +
                    "顶级类别" + "</b>"; 
        tvCm.Nodes.Add(tp);
        DataSet ds = operation.SelectCategoryByPID(pid);//一级类别
        int count = ds.Tables[0].Rows.Count;
        for (int i = 0; i < count; i++)
        {
            TreeNode tn = new TreeNode();
            tn.Value = ds.Tables[0].Rows[i][0].ToString();
            if (ds.Tables[0].Rows[i][3].ToString().CompareTo("False") == 0)
                tn.Text = "<b  style='color:Red' id='" + tn.Value + "' oncontextmenu='return showmenuie5(event)'>" +
                    ds.Tables[0].Rows[i][1].ToString() + "</b>";//未显示
            else
                tn.Text = "<b id='" + tn.Value + "' oncontextmenu='return showmenuie5(event)'>" +
                    ds.Tables[0].Rows[i][1].ToString() + "</b>";
            tp.ChildNodes.Add(tn);
            BuiltTreeView(tn.Value, tn);
        }
    }
    public void BuiltTreeView(string pid, TreeNode pNode)
    {
        DataSet ds = operation.SelectCategoryByPID(pid);//一级类别
        int count = ds.Tables[0].Rows.Count;
        for (int i = 0; i < count; i++)
        {
            TreeNode tn = new TreeNode();
            tn.Value = ds.Tables[0].Rows[i][0].ToString();
            if (ds.Tables[0].Rows[i][3].ToString().CompareTo("False") == 0)
                tn.Text = "<b style='color:Red' id='" + tn.Value + "' oncontextmenu='return showmenuie5(event)'>" +
                    ds.Tables[0].Rows[i][1].ToString() + "</b>";//未显示
            else
                tn.Text = "<b id='" + tn.Value + "' oncontextmenu='return showmenuie5(event)'> " +
                    ds.Tables[0].Rows[i][1].ToString() + "</b>";
            pNode.ChildNodes.Add(tn);
            BuiltTreeView(tn.Value, tn);
        }
    }
}
